package com.klikmee.sms.core.base;

import java.text.MessageFormat;

import org.apache.log4j.Logger;

import com.klikmee.sms.core.base.communicator.DeliveryReport;
import com.klikmee.sms.core.commons.events.AppEvent;
import com.klikmee.sms.core.commons.events.EventListener;

/**
 * Delivery report processor implementation for bulk messages.
 * Can be registered to listen for delivery report announcements.
 * @author makcro
 *
 */
public class BulkDeliveryReportProcessorImpl implements DeliveryReportProcessor, EventListener {

	/**
	 * Logger instance
	 */
	private Logger logger = Logger.getLogger( BulkDeliveryReportProcessorImpl.class );
	
	@Override
	public void process(DeliveryReport deliveryReport) {
		

	}

	/**
	 * Invoked when new delivery report is announced.
	 * Extracts delivery report from event data and calls {@link #process(DeliveryReport)}
	 * 
	 * @param appEvent event instance to process
	 */
	@Override
	public void handleEvent(AppEvent appEvent) {
		// check if this is expected event type
		String eventType = appEvent.getEventType();
		logger.debug( MessageFormat.format( "Received event notification for event [{0}]", eventType ) );
		
		if(eventType.equals(EventManager.DELIVERY_REPORT_ANNOUNCED)){
			// extract event data
			DeliveryReport deliveryReport = appEvent.<DeliveryReport>getData();
			
			// invoke delivery report processing
			process(deliveryReport);
		}
	}

}
